package com.njlime.core.exception;

/**
 * 错误编码
 * Created by Dean on 2017-7-18.
 */
public class ExceptionState {
    public static final int SUCCESS = 0; // 成功
    public static final int PARAM_EXCEPTION = 1; // 参数传递异常
    public static final int DATABASE_EXCEPTION = 2; // 数据库操作异常
    public static final int SESSION_EXCEPTION = 3; // 用户会话异常
    public static final int PERMISSION_EXCEPTION = 4; // 权限异常
    public static final int BUSINESS_EXCEPTION = 5; // 业务异常
    public static final int NEED_AUDIT_EXCEPTION = 6; // 需要审核异常
    public static final int FORMAT_FORMAT = 7; // 参数格式错误异常
    public static final int UNKNOWN_EXCEPTION = 99; // 未知异常
    public static final int MANAGER_EXCEPTION = -1; // 平台管理员操作业务数据异常


    private static final String PARAM_EXCEPTION_MSG = "参数错误";
    private static final String DATABASE_EXCEPTION_MSG = "数据库操作异常";
    private static final String SESSION_EXCEPTION_MSG = "用户未登录或登录已失效";
    private static final String PERMISSION_EXCEPTION_MSG = "用户没有操作的权限";
    private static final String BUSINESS_EXCEPTION_MSG = "服务器繁忙";
    private static final String NEED_AUDIT_EXCEPTION_MSG = "请等待审核完成在进行操作";
    private static final String FORMAT_FORMAT_MSG = "参数格式错误";
    private static final String UNKNOWN_EXCEPTION_MSG = "服务器繁忙";
    private static final String MANAGER_EXCEPTION_MSG = "平台用户无法操作该数据";

    /**
     * 获取默认异常信息
     * @param exceptionCode 错误码
     * @return 默认错误信息
     */
    public static String getExceptionMsg(int exceptionCode){
        switch (exceptionCode){
            case PARAM_EXCEPTION:
                return PARAM_EXCEPTION_MSG;
            case DATABASE_EXCEPTION:
                return DATABASE_EXCEPTION_MSG;
            case SESSION_EXCEPTION:
                return SESSION_EXCEPTION_MSG;
            case PERMISSION_EXCEPTION:
                return PERMISSION_EXCEPTION_MSG;
            case BUSINESS_EXCEPTION:
                return BUSINESS_EXCEPTION_MSG;
            case NEED_AUDIT_EXCEPTION:
                return NEED_AUDIT_EXCEPTION_MSG;
            case FORMAT_FORMAT:
                return FORMAT_FORMAT_MSG;
            case UNKNOWN_EXCEPTION:
                return UNKNOWN_EXCEPTION_MSG;
            case MANAGER_EXCEPTION:
                return MANAGER_EXCEPTION_MSG;
        }
        return "";
    }
}
